#include "addfirstinfo.h"
#include "ui_addfirstinfo.h"
#include "mainwindow.h"

addFirstInfo::addFirstInfo(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::addFirstInfo)
{
    ui->setupUi(this);
    ui->widget_23->hide();
    ui->widget_27->hide();
    ui->textEdit->hide();
    ui->textEdit_3->hide();
    ui->widget_26->hide();
    ui->widget_24->hide();
    ui->widget_25->hide();
    ui->widget_20->hide();
}

addFirstInfo::~addFirstInfo()
{
    delete ui;
}

//既往疾病
void addFirstInfo::on_radioButton_2_clicked()
{
    ui->widget_23->show();
}
void addFirstInfo::on_radioButton_clicked()
{
    ui->widget_23->hide();
}

//目前伴随疾病
void addFirstInfo::on_radioButton_4_clicked()
{
    ui->widget_27->show();
}
void addFirstInfo::on_radioButton_3_clicked()
{
    ui->widget_27->hide();
}

//胸腺疾病
void addFirstInfo::on_radioButton_6_clicked()
{
    ui->textEdit->show();
}
void addFirstInfo::on_radioButton_5_clicked()
{
    ui->textEdit->hide();
}

//肌无力危像
void addFirstInfo::on_radioButton_8_clicked()
{
    ui->textEdit_3->show();
}
void addFirstInfo::on_radioButton_7_clicked()
{
    ui->textEdit_3->hide();
}

//抗体
void addFirstInfo::on_radioButton_9_clicked()
{
    ui->widget_26->show();
}
void addFirstInfo::on_radioButton_10_clicked()
{
    ui->widget_26->hide();
}

//抽血
void addFirstInfo::on_radioButton_12_clicked()
{
    ui->widget_24->show();
}
void addFirstInfo::on_radioButton_11_clicked()
{
    ui->widget_24->hide();
}

//技检
void addFirstInfo::on_radioButton_14_clicked()
{
    ui->widget_25->show();
}
void addFirstInfo::on_radioButton_13_clicked()
{
    ui->widget_25->hide();
}

//MGFA
void addFirstInfo::on_radioButton_16_clicked()
{
    ui->widget_20->show();
}
void addFirstInfo::on_radioButton_15_clicked()
{
    ui->widget_20->hide();
}

void addFirstInfo::on_btn_submit_clicked()
{
    QString time = ui->lineEdit->text();  //就诊时间
    QString symptom = "";  //首发症状
    bool flag = false;
    if(ui->checkBox->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox->text();
        flag = true;
    }
    if(ui->checkBox_2->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_2->text();
        flag = true;
    }
    if(ui->checkBox_3->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_3->text();
        flag = true;
    }
    if(ui->checkBox_4->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_4->text();
        flag = true;
    }
    if(ui->checkBox_5->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_5->text();
        flag = true;
    }
    if(ui->checkBox_6->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_6->text();
        flag = true;
    }
    if(ui->checkBox_7->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_7->text();
        flag = true;
    }
    if(ui->checkBox_8->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_8->text();
        flag = true;
    }
    if(ui->checkBox_9->checkState())
    {
        if(flag)
        {
            symptom += "、";
        }
        symptom += ui->checkBox_9->text();
        flag = true;
    }
    QString age = ui->lineEdit_3->text();  //年龄
    QString passtime = ui->lineEdit_4->text();  //经历时间
    QString height = ui->lineEdit_5->text();  //身高
    QString weight = ui->lineEdit_6->text();  //体重
    QString smoke = ui->lineEdit_7->text();  //吸烟史
    QString pill = "";  //既往疾病
    flag = false;
    if(ui->radioButton->isChecked())
    {
        pill = "无";
    }
    else if(ui->radioButton_2->isChecked())
    {
        if(ui->checkBox_10->checkState())
        {
            if(flag)
            {
                pill += "、";
            }
            pill += ui->checkBox_10->text();
            flag = true;
        }
        if(ui->checkBox_11->checkState())
        {
            if(flag)
            {
                pill += "、";
            }
            pill += ui->checkBox_11->text();
            flag = true;
        }
        if(ui->checkBox_12->checkState())
        {
            if(flag)
            {
                pill += "、";
            }
            pill += ui->checkBox_12->text();
            flag = true;
        }
        if(ui->checkBox_13->checkState())
        {
            if(flag)
            {
                pill += "、";
            }
            pill += ui->checkBox_13->text();
            flag = true;
        }
        if(ui->checkBox_14->checkState())
        {
            if(flag)
            {
                pill += "、";
            }
            pill += ui->checkBox_14->text();
            flag = true;
        }
        if(QString::compare(ui->lineEdit_2->text(), "") != 0)
        {
            pill += "、";
            pill += ui->lineEdit_2->text();
        }
    }
    QString cill = "";  //伴随疾病
    flag = false;
    if(ui->radioButton_3->isChecked())
    {
        cill = "无";
    }
    else if(ui->radioButton_4->isChecked())
    {
        if(ui->checkBox_15->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_15->text();
            flag = true;
        }
        if(ui->checkBox_16->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_16->text();
            flag = true;
        }
        if(ui->checkBox_17->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_17->text();
            flag = true;
        }
        if(ui->checkBox_18->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_18->text();
            flag = true;
        }
        if(ui->checkBox_19->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_19->text();
            flag = true;
        }
        if(ui->checkBox_20->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_20->text();
            flag = true;
        }
        if(ui->checkBox_21->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_21->text();
            flag = true;
        }
        if(ui->checkBox_22->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_22->text();
            flag = true;
        }
        if(ui->checkBox_23->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_23->text();
            flag = true;
        }
        if(ui->checkBox_24->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_24->text();
            flag = true;
        }
        if(ui->checkBox_25->checkState())
        {
            if(flag)
            {
                cill += "、";
            }
            cill += ui->checkBox_25->text();
            flag = true;
        }
        if(QString::compare(ui->lineEdit_8->text(), "") != 0)
        {
            cill += "、";
            cill += ui->lineEdit_8->text();
        }
    }
    QString till = "";  //胸腺疾病
    if(ui->radioButton_5->isChecked())
    {
        till = "未查";
    }
    else if(ui->radioButton_6->isChecked())
    {
        till += ui->textEdit->toPlainText();
    }
    QString mill = "";  //肌无力
    if(ui->radioButton_7->isChecked())
    {
        mill = "无";
    }
    else if(ui->radioButton_8->isChecked())
    {
        mill += ui->textEdit_3->toPlainText();
    }
    QString scale = ui->textEdit_2->toPlainText();  //量表
    QString diagnosis = ui->textEdit_4->toPlainText();  //诊断
    QString method = ui->textEdit_5->toPlainText();  //治疗方案
    QString MGFA = "";  //MGFA
    if(ui->radioButton_15->isChecked())
    {
        MGFA = "无干预";
    }
    else if(ui->radioButton_17->isChecked())
    {
        MGFA = "完全缓解";
    }
    else if(ui->radioButton_18->isChecked())
    {
        MGFA = "药物缓解";
    }
    else if(ui->radioButton_19->isChecked())
    {
        MGFA = "微小缓解";
    }
    else if(ui->radioButton_20->isChecked())
    {
        MGFA = "改善";
    }
    else if(ui->radioButton_21->isChecked())
    {
        MGFA = "无变化";
    }
    else if(ui->radioButton_22->isChecked())
    {
        MGFA = "加重";
    }
    else if(ui->radioButton_23->isChecked())
    {
        MGFA = "恶化";
    }
    else if(ui->radioButton_24->isChecked())
    {
        MGFA = "死亡";
    }
    auto ptr = MainWindow::getinstance();
    QString id = ptr->us.getUserSqlId();
    ptr->addFirstInfoById(id, time, symptom, age, passtime, height, weight, smoke, pill, cill, till, mill, antibody_path, blood_path, technical_path, scale, scale_path, diagnosis, diagnosis_path, method, MGFA);
    Info info = ptr->getFirstInfoById(id.toInt());
    ptr->us.load(info);
    this->hide();
    ptr = nullptr;
}

void addFirstInfo::on_btn_cancel_clicked()
{
    this->hide();
}

//抗体图片上传
void addFirstInfo::on_pushButton_clicked()
{
    antibody_path = QFileDialog::getOpenFileName(nullptr, "文件上传", "", "");
    qDebug() << antibody_path;
    QImage image;
    image.load(antibody_path);
    QPixmap pixmap = QPixmap::fromImage(image);
    int width = ui->label_20->width();
    int height = ui->label_20->height();
    QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_20->setPixmap(fitpixmap);
}

//抽血图片上传
void addFirstInfo::on_pushButton_2_clicked()
{
    blood_path = QFileDialog::getOpenFileName(nullptr, "文件上传", "", "");
    qDebug() << blood_path;
    QImage image;
    image.load(blood_path);
    QPixmap pixmap = QPixmap::fromImage(image);
    int width = ui->label_21->width();
    int height = ui->label_21->height();
    QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_21->setPixmap(fitpixmap);
}

//技检图片上传
void addFirstInfo::on_pushButton_3_clicked()
{
    technical_path = QFileDialog::getOpenFileName(nullptr, "文件上传", "", "");
    qDebug() << technical_path;
    QImage image;
    image.load(technical_path);
    QPixmap pixmap = QPixmap::fromImage(image);
    int width = ui->label_22->width();
    int height = ui->label_22->height();
    QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_22->setPixmap(fitpixmap);
}

//量表图片上传
void addFirstInfo::on_pushButton_4_clicked()
{
    scale_path = QFileDialog::getOpenFileName(nullptr, "文件上传", "", "");
    qDebug() << scale_path;
    QImage image;
    image.load(scale_path);
    QPixmap pixmap = QPixmap::fromImage(image);
    int width = ui->label_23->width();
    int height = ui->label_23->height();
    QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_23->setPixmap(fitpixmap);
}

//诊断图片上传
void addFirstInfo::on_pushButton_5_clicked()
{
    diagnosis_path = QFileDialog::getOpenFileName(nullptr, "文件上传", "", "");
    qDebug() << diagnosis_path;
    QImage image;
    image.load(diagnosis_path);
    QPixmap pixmap = QPixmap::fromImage(image);
    int width = ui->label_24->width();
    int height = ui->label_24->height();
    QPixmap fitpixmap = pixmap.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ui->label_24->setPixmap(fitpixmap);
}
